Skip to content

Conversation

@Kenneth-W-Chen
Copy link
Member

Summary

  • Created a DiscordPHP script to verify a user's UNT email address in Discord.
  • Added a form to do the same thing but on the dues/paid page.
    • The form shows up before the Discord link, so the user must verify their UNT email before linking their Discord account through the dues/paid page. Afterwards, the Good Standing and Verified roles are added if the user is in good standing and has verified their email.
  • Created a function to add application commands to the Discord bot (in api/discord/bot.php not api/discord/bots/admin.php).

DB Changes

Other changes

  • Sign-up process adjusted for the users entry creation during the Discord verification process (if applicable; see notes)
  • After paying dues and linking their Discord account, the Verified role is added along with the Good Standing role.
  • Added a function to check if user has a verified UNT email.
  • Updated config.php with Verified role ID and email token generation rate limit (in seconds, so 5 minutes).
  • Fixed a bug with the RDMailForm/jquery-form plugin where server errors (non-success status codes; not the INVALID or ERROR response messages) weren't properly displaying because the result parameter was an XHR instead of the response text. See 071fbb1 for change
  • Extracted a function from the RDMailForm plugin code since the email verification form uses the same snackbar logic.
  • Added a function to discord.php Discord bot to add the verified role to a user, similar to what's used for the good standing role.

Notes

  • PHP version needs to be 8.1.2 or greater for the DiscordPHP script to work and various other parts of this PR (because of usage of mysqli::fetch_column and maybe? other mysqli functions only available in PHP8).
  • api/discord/application-commands/register.php only needs to be run when api/discord/application-commands/commands.json changes. If a new/old command needs to be added/edited, make the changes in commands.json and run register.php. There currently isn't any functionality to delete application commands.
  • When a user creates an account on the website, if they sign up with their UNT email address that was already used in Discord to verify themselves, then the users entry is updated instead of making a new entry. (077128b)
  • I made a separate function for the email verification form on the website, instead of using the pre-existing RDMailForm plugin, because I needed to change the form a bit after the first request. The other option was making the user go through an additional page after submitting their UNT email. See script.js changes

Testing

  • Application command registration works as long as the bot has permissions to register the commands and the guild ID is set properly.
  • Web flow works properly besides adding any roles.
  • DiscordPHP script is tested for adding the role, responding to application commands, and generating a token. This was done on my own system instead of the dev server.
  • Couldn't test the DiscordPHP script to the following extent:
    • All deferred interaction responses are updated via updateOriginalResponse().
    • Anything directly related to the database (e.g., deleting tokens on regeneration or checking if a user has reached the token ratelimit)

Update discord_id field to use same type as in users table

Update sample.config with DISCORD_VERIFIED_ROLE_ID constant
Reformatting and reworded some comments
Updates a user entry which was created through the discord verification process (only has the unt_email and discord_id fields) with the website account details instead of making a new user account. This only happens if they sign up with the same email as in unt_email
PHP documentation incorrectly states that it works for UPDATE statements; it does not
Moved the token ratelimit const to the config file since it's used for both the discord and website flows
PHP Storm incorrectly tries to remove the parentheses which causes the issue
…kend issues

Plugin doesn't like newly created input fields and changes to the form html
This fix applies to RDMailForm too

Added validation
Fix snackbar not disappearing for initial token request
Fix token form showing up regardless of verification status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants